<template>
  <div>
    <navbar></navbar>
    <div class="content">
      <div class="columns">
        <div class="column">
          <div style="margin: 50px 5% 0px 10%">
            <!-- <b-table :data="data" :columns="columns"></b-table> -->
            <h4>查看所有用户</h4>
            <b-tabs>
              <b-tab-item label="Table">
                <b-table
                  :data="data"
                  :columns="columns"
                  :selected.sync="selected"
                  focusable
                >
                </b-table>
              </b-tab-item>

              <b-tab-item label="Selected">
                <pre>{{ selected }}</pre>
              </b-tab-item>
            </b-tabs>
            <b-field label="Level" type="is-success">
              <b-select
                placeholder="Select a character"
                v-model="the_level_we_change"
              >
                <option value="user">user</option>
                <option value="admin">admin</option>
                <option value="banned">banned</option>
              </b-select>
              <b-button @click="submitLevel" style="margin-left: 1%"
                >更改等级</b-button
              >
            </b-field>
          </div>
        </div>
        <div class="column">
          <div style="margin: 50px 10% 0px 5%">
            <!-- <b-table :data="data" :columns="columns"></b-table> -->
            <h4>查看各分区最活跃用户</h4>
            <b-tabs>
              <b-tab-item label="Table">
                <b-table
                  :data="data1"
                  :columns="columns1"
                  :selected.sync="selected"
                  focusable
                >
                </b-table>
              </b-tab-item>

              <b-tab-item label="Selected">
                <pre>{{ selected }}</pre>
              </b-tab-item>
            </b-tabs>
            <b-field label="选择分区">
              <b-select
                placeholder="Select a area"
                v-model="the_tag_we_change"
                Required
              >
                <option value="生活">生活</option>  
                <option value="知识">知识</option>
                <option value="动画">动画</option>
                <option value="数码">数码</option>
                <option value="影视">影视</option>
                <option value="音乐">音乐</option>
                <option value="时尚">时尚</option>
                <option value="娱乐">娱乐</option>
                <option value="舞蹈">舞蹈</option>
                <option value="新闻">新闻</option>
                <option value="萌宠">萌宠</option>
                <option value="游戏">游戏</option>
              </b-select>
              <b-button @click="tag_change" style="margin-left: 1%">
                更改分区
              </b-button>
            </b-field>
            <b-field label="Level" type="is-success">
              <b-select
                placeholder="Select a character"
                v-model="the_level_we_change"
              >
                <option value="user">user</option>
                <option value="admin">admin</option>
                <option value="banned">banned</option>
              </b-select>
              <b-button @click="submitLevel" style="margin-left: 1%"
                >更改等级</b-button
              >
            </b-field>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import navbar from "../components/common/navbar.vue";
export default {
  name: "UserCenter",
  components: { navbar },
  data() {
    return {
      locale: "en-CA",
      begin_time: "",
      end_time: "",
      the_level_we_change: "",
      the_tag_we_change: "生活",
      selected: {},
      data: [],
      data1: [],
      columns: [
        {
          field: "username.String",
          label: "Username",
          width: "40",
        },
        {
          field: "uid",
          label: "Uid",
        },
        {
          field: "honor.Int32",
          label: "Honor",
        },
        {
          field: "tail.String",
          label: "Tail",
          centered: true,
        },
        {
          field: "level.String",
          label: "Level",
        },
      ],
      columns1: [
        {
          field: "username.String",
          label: "Username",
          width: "40",
        },
        {
          field: "uid",
          label: "Uid",
        },
        {
          field: "honor.Int32",
          label: "Honor",
        },
        {
          field: "tail.String",
          label: "Tail",
          centered: true,
        },
        {
          field: "level.String",
          label: "Level",
        },
        {
          field: "countnum",
          label: "帖子数",
        },
      ],
    };
  },
  methods: {
    async searchtime(){
      // this.begin_time.setDate(this.begin_time.getDate() + 1);
      console.log(this.begin_time);
      // this.end_time.setDate(this.end_time.getDate() + 1);
      console.log(this.end_time);
      this.$router.push({
        path:"/search",
        query:{
          begin_time:this.begin_time.toISOString(),
          end_time:this.end_time.toISOString(),
          status:"3",
        }
      });
    },
    //根据tag查询分区下最活跃用户
    async tag_change() {
      let res = await this.$http.get(
        "/go/pic/searchMVP/" + this.the_tag_we_change,
        {
          headers: {
            pass: "",
            Authorization: "Bearer " + (await localStorage.getItem("token")),
          },
        }
      );
      this.data1 = res.data.data;
      console.log(this.data1);
      if (res.data.status == 20000) {
        console.log("更换tag成功");
      }
    },
    //改变用户的权限等级
    async submitLevel() {
      let res = await this.$http.post(
        "/go/socail/updateLevel",
        {
          uid: this.selected.uid,
          level: this.the_level_we_change,
        },
        {
          headers: {
            pass: "",
            Authorization: "Bearer " + (await localStorage.getItem("token")),
          },
        }
      );
      if (res.data.status == 20000) {
        await this.$vs.notification({ title: "提交成功" });
        this.$router.go(0);
      }
    },
  },
  //before create fx
  async beforeCreate() {
    if (this.$route.query.level == null) {
      this.$router.push("/");
    }
    console.log(this.$route.query.level);
    console.log(this.$route.query.username);
    console.log(this.$route.query.uid);
    //管理员页面显示用户列表
    let res = await this.$http.get("/go/socail/allSocail", {
      headers: {
        pass: "",
        Authorization: "Bearer " + (await localStorage.getItem("token")),
      },
    });
    this.data = res.data.data;
    console.log(this.data);
    let res1 = await this.$http.get("/go/pic/searchMVP/" + "生活", {
      headers: {
        pass: "",
        Authorization: "Bearer " + (await localStorage.getItem("token")),
      },
    });
    console.log(res1);
    this.data1 = res1.data.data;
  },
};
</script>
<style scoped>
.content {
  margin-top: 70px;
  min-height: calc(100vh - 34px);
}
</style>